package com.netdisk.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.netdisk.entity.UserActivity;
import com.netdisk.mapper.UserActivityMapper;
import com.netdisk.service.UserActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户活动日志服务实现类
 */
@Slf4j
@Service
public class UserActivityServiceImpl extends ServiceImpl<UserActivityMapper, UserActivity> implements UserActivityService {

    @Autowired
    private UserActivityMapper userActivityMapper;

    @Override
    public List<UserActivity> getRecentActivities(Integer userId, Integer limit) {
        log.info("获取用户ID={}的最近{}条活动日志", userId, limit);
        return userActivityMapper.selectRecentActivities(userId, limit);
    }

    @Override
    public boolean recordActivity(Integer userId, Integer fileId, String fileName, 
                                String actionType, String description, 
                                String ipAddress, String userAgent) {
        log.info("记录用户活动: userId={}, fileId={}, fileName={}, actionType={}", 
                userId, fileId, fileName, actionType);
        
        UserActivity activity = new UserActivity();
        activity.setUserId(userId);
        activity.setFileId(fileId);
        activity.setFileName(fileName);
        activity.setActionType(actionType);
        activity.setDescription(description);
        activity.setIpAddress(ipAddress);
        activity.setUserAgent(userAgent);
        activity.setCreatedAt(LocalDateTime.now());
        
        return this.save(activity);
    }
} 